package com.sitia.jd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.sitia.common.annotation.Log;
import com.sitia.common.core.controller.BaseController;
import com.sitia.common.core.domain.AjaxResult;
import com.sitia.common.enums.BusinessType;
import com.sitia.jd.domain.MxAvailableGoods;
import com.sitia.jd.service.IMxAvailableGoodsService;
import com.sitia.common.utils.poi.ExcelUtil;
import com.sitia.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 可用商品Controller
 * 
 * @author sitia
 * @date 2024-06-23
 */
@RestController
@RequestMapping("/available/goods")
public class MxAvailableGoodsController extends BaseController
{
    @Autowired
    private IMxAvailableGoodsService mxAvailableGoodsService;

    /**
     * 查询可用商品列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MxAvailableGoods mxAvailableGoods)
    {
        startPage();
        List<MxAvailableGoods> list = mxAvailableGoodsService.selectMxAvailableGoodsList(mxAvailableGoods);
        return getDataTable(list);
    }

    /**
     * 导出可用商品列表
     */
    @Log(title = "可用商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MxAvailableGoods mxAvailableGoods)
    {
        List<MxAvailableGoods> list = mxAvailableGoodsService.selectMxAvailableGoodsList(mxAvailableGoods);
        ExcelUtil<MxAvailableGoods> util = new ExcelUtil<MxAvailableGoods>(MxAvailableGoods.class);
        util.exportExcel(response, list, "可用商品数据");
    }

    /**
     * 获取可用商品详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(mxAvailableGoodsService.selectMxAvailableGoodsById(id));
    }

    /**
     * 新增可用商品
     */
    @Log(title = "可用商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MxAvailableGoods mxAvailableGoods)
    {
        return toAjax(mxAvailableGoodsService.insertMxAvailableGoods(mxAvailableGoods));
    }

    /**
     * 修改可用商品
     */
    @Log(title = "可用商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MxAvailableGoods mxAvailableGoods)
    {
        return toAjax(mxAvailableGoodsService.updateMxAvailableGoods(mxAvailableGoods));
    }

    /**
     * 删除可用商品
     */
    @Log(title = "可用商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(mxAvailableGoodsService.deleteMxAvailableGoodsByIds(ids));
    }


    /**
     * 导入可用商品Excel
     *
     * @param fileList 文件
     * @param
     * @return
     */
    @PostMapping("/importAvailableExcel")
    public AjaxResult importIdAndOrderExcel(@RequestParam("fileList") List<MultipartFile> fileList) {

        return AjaxResult.success(mxAvailableGoodsService.importAvailableExcel(fileList, null));
    }
}
